package com.alibaba.shopping_cart_service.listener;

import com.alibaba.shopping_common.pojo.CartGoods;
import com.alibaba.shopping_common.service.CartService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName SyncCartListener
 * @Description 监听商品更新的消息
 * @Author Leo
 * @Date 2024/12/18 14:37
 */
@Service
@RocketMQMessageListener(topic = "sync_cart_queue",consumerGroup = "sync_consumer_group")
public class SyncCartListener implements RocketMQListener<CartGoods> {

    @Autowired
    private CartService cartService;

    /**
     * 更新Redis中购物车商品数据
     * @param cartGoods
     */
    @Override
    public void onMessage(CartGoods cartGoods) {
        System.out.println("更新Redis中购物车商品数据");
        cartService.refreshRedisCartGoods(cartGoods);
    }
}




